/*
 * @Author: M_xiaohan
 * @Date: 2018-05-01 15:51:11
 * @Last Modified by: M_xiaohan
 * @Last Modified time: 2018-05-08 13:49:54
 */
import { getInternalTradeTypeList } from '../services/internaltradetype';
// import { getCarAllList } from '../services/car';

export default {
  namespace: 'internaltradetype',

  state: {
    InternaltradetypeList: [],
    isError: false,
    carListNum: null,
  },

  effects: {
    *fetchInternaltradetypeList({ payload }, { call, put }) {
      const response = yield call(getInternalTradeTypeList, payload);
      if (response.code === 0) {
        yield put({
          type: 'getInternaltradetypeListData',
          payload: response.data,
        });
      } else {
        yield put({
          type: 'errorMsg',
          payload: {
            code: response.code,
            msg: response.msg,
          },
        });
      }
    },
    // *getCarList({ payload }, { call, put }) {
    //   const params = {
    //     customerId: 1,
    //   };
    //   const response = yield call(getCarList, { ...params });
    //   console.log(4444, response);
    //   yield put({ 
    //     type: 'getCarListNum',
    //     payload: {
    //       ...response.data,
    //     },
    //   });
    // },
  },

  reducers: {
    errorMsg(state, action) {
      return {
        ...state,
        isError: true,
        ...action.payload,
      };
    },
    getInternaltradetypeListData(state, action) {
      return {
        ...state,
        InternaltradetypeList: action.payload.list,
      };
    },
  },
  // subscriptions: {
  //   setup({ dispatch }) {
  //     dispatch({
  //       type: 'global/getCarAllData',
  //       payload: {
  //         pageNum: 0,
  //       },
  //     });
  //   },
  // },
};
